import redis

class myredis():
    def __init__(self):
        self.conn = redis.Redis(host="localhost",port=6379)

    def insert_values(self,key,value):
        for i in value:
            self.conn.sadd(key,i)

    def get_values(self,key):
        lst = []
        for i in self.conn.smembers(key):
            lst.append(str(i,encoding="utf8"))
        return lst

    def hset_key(self,key,key1,value):
        self.conn.hset(key,key1,value)

    def hget_keys(self,key):
        return self.conn.hgetall(key)

    def hget_key(self,key,key1):
        return self.conn.hget(key,key1)
    def get_srt(self,key):
        valus = self.conn.get(key)
        if valus:
            valus = str(valus,encoding="utf8")
        return valus
    def set_to(self,key,values,time=0):
        if time==0:
            self.conn.set(key,values)
        else:
            self.conn.setex(key,time,values)

r = myredis()
# r.insert_values("interface1",["/role"])
# print(r.get_values("interface1"))
